CC = gcc
CFLAGS = -Wall -Wextra -O2
LDFLAGS = -lm

COMMON_SRC = knapsack.c
COMMON_OBJ = $(COMMON_SRC:.c=.o)

TARGETS = bruteforce_knapsack dynamic_knapsack greedy_knapsack backtracking_knapsack

all: $(TARGETS)

bruteforce_knapsack: bruteforce_main.o $(COMMON_OBJ)
	$(CC) $^ -o $@ $(LDFLAGS)

dynamic_knapsack: dynamic_main.o $(COMMON_OBJ)
	$(CC) $^ -o $@ $(LDFLAGS)

greedy_knapsack: greedy_main.o $(COMMON_OBJ)
	$(CC) $^ -o $@ $(LDFLAGS)

backtracking_knapsack: backtracking_main.o $(COMMON_OBJ)
	$(CC) $^ -o $@ $(LDFLAGS)

%.o: %.c
	$(CC) $(CFLAGS) -c $< -o $@

clean:
	rm -f *.o $(TARGETS) *_run_time.txt *_fakecode.txt *_timeout.txt 